﻿using System.Collections.Generic;
using System.Linq;

namespace DataScripter.Scripting.Filters
{
    class FilterCombination : IFilterCombination
    {
        private string Separator { get; set; }

        protected FilterCombination(string separator)
        {
            Separator = separator;
        }

        readonly IList<ITableFilter> _filters = new List<ITableFilter>();

        public void Add(ITableFilter filter)
        {
            _filters.Add(filter);
        }

        public IEnumerable<ITableFilter> Filters
        {
            get { return _filters; }
        }

        public string ProduceFilter()
        {
            return string.Join(" " + Separator + " ", _filters.Select(f => f.ProduceFilter()).ToArray());
        }

        public string ProduceWhereClause()
        {
            string netWhereClause = ProduceFilter();
            return string.IsNullOrEmpty(netWhereClause) ? string.Empty : " WHERE " + netWhereClause;
        }
    }
}